import request from "@/util/request";
import type {Cart} from "@/api/cart/types";

const API: string = '/dishes-service/cart'

/**
 * 添加或修改购物车
 */
export const saveOrUpdate = (form: Cart) => {
    return request<any, any, Cart>({
        url: API,
        method: 'post',
        data: form
    })
}

/**
 * 查询购物车菜品列表
 */
export const getCartList = () => {
    return request<Cart[], Cart[]>({
        url: API + '/list',
        method: 'get'
    })
}

/**
 * 删除购物车中的菜品
 */
export const deleteCart = (id: any) => {
    return request<any, any>({
        url: API + `/dishes/${id}`,
        method: 'delete'
    })
}

/**
 * 清空购物车
 */
export const clearCart = () => {
    return request<any, any>({
        url: API,
        method: 'delete'
    })
}